package com.study.mr.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordCountCombiner extends Reducer<Text,IntWritable,Text,IntWritable>{
    private Text outk=new Text();
    private IntWritable outv=new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        //1，遍历values
        int total=0;
        for (IntWritable value : values) {
            total+=value.get();
        }

        //2.封装key和value
        outk.set(key);
        outv.set(total);
        context.write(outk,outv);
    }

}
